package cn.wyl.controller;

import cn.wyl.domain.Course;
import cn.wyl.service.ICourseService;
import cn.wyl.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class CourseController {

    @Autowired
    private ICourseService courseService;
    
    @PostMapping("/course/save")
    public AjaxResult save(@RequestBody Course course){
        try {
            System.out.println(course);
            courseService.save(course);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }

    @GetMapping("/course/{id}")
    public AjaxResult findById(@PathVariable("id") Long id){
        Course course = courseService.loadById(id);
        return new AjaxResult().setResultObj(course);
    }

    @PostMapping("/course/upd")
    public AjaxResult upd(@RequestBody Course course){
        try {
            System.out.println(course);
            courseService.upd(course);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error();
        }
    }
}
